<include file="../header"/>
<body>
<div class="wraper">
    <div class="load">
        <img class="load-bee" src="/assets/repairnew/images/load-bee.png"/>
    </div>
    <div class="top">
        <p class="">
            <a href="{BEESCRM::U('repairnew/repairnew/index',array('repairId'=>$repairId,'type'=>$type))}"
               class="iconfont icon-zuo fl-left"></a>
            <span class="fl-left">订单详情<if condition="$data['order_type'] eq 4">[巡检订单]<elseif
                    condition="$data['order_type'] eq 2"/>[返修订单]<elseif condition="$data['order_type'] eq 3"/>[转派订单]<elseif
                    condition="$data['order_type'] eq 5"/>[补录订单]<elseif
                    condition="$data['order_type'] eq 6"/>[紧急订单]</if></span>
            <a href="{BEESCRM::U('repairnew/repairnew/index',array('repairId'=>$repairId,'type'=>$type))}"
               class="iconfont icon-shouye text-right fl-right"></a>
        </p>
    </div>
    <p class="title">报修单号</p>
    <p class="list" style="margin-bottom: 10px;">{BEESCRM:$data.order_sn}</p>
    <!--已下单-->
    <div class="dialog clearfix">
        <span class="left-big"></span>
        <span class="left-middle"></span>
        <p>
            <span class="circle gray"></span>已下单<span class="time fl-right">{BEESCRM:$data.create_time|date='Y-m-d H:i',###}</span>
        </p>
        <if condition="$data['order_type'] neq 4">
            <p><span>报修人：</span> {BEESCRM:$data['real_name']|mb_substr=0,1,'utf8'}某某</p>
        </if>
        <if condition="$data['mobile']"><p><span>联系电话：</span> <a href="tel://{BEESCRM:$data.mobile}">{BEESCRM:$data.mobile}</a>
        </p></if>
        <p><span>报修区域：</span> {BEESCRM:$data.community_name}</p>
        <p><span>报修地址：</span> {BEESCRM:$data.building_name}{BEESCRM:$data.room_name}{BEESCRM:$data.detail_address}</p>
        <p><span>报修内容：</span> {BEESCRM:$data.content}</p>
        <P><span>报修项目：</span> {BEESCRM:$project_name}　　{BEESCRM:$project_child_name}</P>
        <if condition="$imageList">
            <volist name="imageList" id="vo">
                <if condition="$vo['type'] eq 0"><img class="picture fl-left" src="{BEESCRM:$vo.url}"/></if>
            </volist>
        </if>


        <!--已转为非日常订单 end-->

        <if condition="$data['status'] lt ORDER_RECEIVED and $data['audit'] neq 2 and $data['order_type_id'] eq 0">
            <a href="javascript:;" class="confirm fl-right" id="confirm">确认接单</a>
        </if>
    </div>

    <!--已转为非日常订单 在刚下单就转-->
    <if condition="$data['order_type_id'] neq 0 and ($data['nodaily_time'] elt $data['confirm_time'] or $data['status'] lt ORDER_RECEIVED)">
        <div class="dialog clearfix">
            <span class="left-big"></span>
            <span class="left-middle"></span>
            <p>
                <span class="circle orange"></span>
                已转为非日常订单
                <span class="time fl-right">{BEESCRM:$data['nodaily_time']|date='Y-m-d H:i',###}</span>
            </p>
        </div>
    </if>

    <!--已接单-->
    <if condition="$data['status'] egt ORDER_RECEIVED and $data['order_type'] neq 5">
        <div class="dialog clearfix">
            <span class="left-big"></span>
            <span class="left-middle"></span>
            <p>
                <span class="circle gray"></span>已接单
                <if condition="$receiveReduceLog"><font color='red'>(超时)</font></if>
                <span class="time fl-right"><if condition="$data.confirm_time neq 0">{BEESCRM:$data.confirm_time|date='Y-m-d H:i',###} <else/>{BEESCRM:$data.create_time|date='Y-m-d H:i',###} </if></span>
            </p>
            <p><span>受理人：</span> {BEESCRM:$repairman['real_name']|mb_substr=0,1,'utf8'}师傅</p>
            <p><span>受理人电话</span> <a href="tel://{BEESCRM:$repairman.mobile}">{BEESCRM:$repairman.mobile}</a></p>
            <P><span>处理说明:</span>{BEESCRM:$data.send_remark}</P>
        </div>
    </if>

    <!--已转为非日常订单 在已接单后就转-->
    <if condition="$data['order_type_id'] neq 0 and ($data['nodaily_time'] elt $data['attend_time'] or $data['status'] eq ORDER_RECEIVED)">
        <div class="dialog clearfix">
            <span class="left-big"></span>
            <span class="left-middle"></span>
            <p>
                <span class="circle orange"></span>
                已转为非日常订单
                <span class="time fl-right">{BEESCRM:$data['nodaily_time']|date='Y-m-d H:i',###}</span>
            </p>
            <p><span>转为非日常订单备注:</span>{BEESCRM:$data.nodaily_remark}</p>
        </div>
    </if>
    <!--已转为非日常订单 end-->

    <!--到场-->
    <if condition="$data['status'] eq ORDER_RECEIVED and $data['order_type'] neq 4 and $data['order_type_id'] eq 0">
        <div class="dialog clearfix">
            <span class="right-big"></span>
            <span class="right-middle"></span>
            <p>
                <span class="circle green"></span>待到场
                <if condition="$arriveReduceLog"><font color='red'>(已超时)</font></if>
            </p>
            <p><span>到场操作：</span>
                {BEESCRM:$repairman['real_name']|mb_substr=0,1,'utf8'}师傅　工号：{BEESCRM:$repairman['number']}</p>
            <p><span>到场拍照：</span></p>

            <div class="upload-img clearfix">
                <div class="imgbox fl-left">
                    <span id="ps"><img style="width:50px;height:50px;" id="photo" src=""/></span>
                </div>
                <div class="add-img fl-left">
                    <input class="file-input" type="file" name="upload-file" id="photo_input"
                           style="width: 58px;height: 58px;"/>
                    <span class="iconfont icon-tianjia tianjia"></span>
                    <input type="hidden" id="photo_path" value="">
                </div>
            </div>


            <div class="label-btn clearfix">
                <a href="javascript:void(0)" class="submit apply">物料申请</a>
                <a href="javascript:void(0)" class="submit" id="arrive">已到现场</a>
            </div>
        </div>
    </if>

    <!-- 巡检订单状态-->
    <if condition="$data['status'] eq ORDER_RECEIVED and $data['order_type'] eq 4 and $data['audit'] eq 1">
        <div class="dialog clearfix">
            <span class="right-big"></span>
            <span class="right-middle"></span>
            <p>
                <span class="circle green"></span>待到场
            </p>
            <p><span>到场操作：</span>
                {BEESCRM:$repairman['real_name']|mb_substr=0,1,'utf8'}师傅　工号：{BEESCRM:$repairman['number']}</p>
            <p><span>到场拍照：</span></p>

            <div class="upload-img clearfix">
                <div class="imgbox fl-left">
                    <span id="ps"><img style="width:50px;height:50px;" id="photo" src=""/></span>
                </div>
                <div class="add-img fl-left">
                    <input class="file-input" type="file" name="upload-file" id="photo_input"
                           style="width: 58px;height: 58px;"/>
                    <span class="iconfont icon-tianjia tianjia"></span>
                    <input type="hidden" id="photo_path" value="">
                </div>
            </div>
            <!--前台录入的巡检订单-->
            <if condition="$data['orgin'] eq 0">
                <div class="label-btn clearfix">
                    <a href="javascript:void(0)" class="submit apply">物料申请</a>
                    <a href="javascript:void(0)" class="submit" id="arrive">已到场</a>
                </div>
                <else/>

                <!--后台录入的巡检订单-->
                <div class="label-btn clearfix">
                    <a href="javascript:void(0)" class="submit apply">物料申请</a>
                    <a href="javascript:void(0)" class="submit" id="arrive">已到场</a>
                </div>
            </if>
        </div>
    </if>
    <if condition="$repair['audit'] eq 1">
        <if condition="$data['status'] eq ORDER_RECEIVED and $data['order_type'] eq 4 and $data['audit'] eq 0">
            <div class="dialog clearfix">
                <span class="left-big"></span>
                <span class="left-middle"></span>
                <p>
                    <span class="circle gray"></span>待审核
                </p>
            </div>
        </if>
    </if>
    <if condition="$repair['audit'] eq 0">
        <if condition=" $data['order_type'] eq 4 ">
            <div class="dialog clearfix">
                <span class="left-big"></span>
                <span class="left-middle"></span>
                <p>
                    <span class="circle gray"></span>已审核
                </p>
            </div>
        </if>
    </if>
    <!--巡检-->
    <if condition="$data['audit'] eq 2 and $data['order_type'] eq 4">
        <div class="dialog clearfix">
            <span class="left-big"></span>
            <span class="left-middle"></span>
            <p>
                <span class="circle gray"></span>审核未通过
            </p>
        </div>
    </if>

    <!--已到场-->
    <if condition="$data['status'] egt ORDER_ATTEND and $data['order_type'] neq 6 and $data['order_type'] neq 5">
        <div class="dialog clearfix">
            <span class="left-big"></span>
            <span class="left-middle"></span>
            <p>
                <span class="circle gray"></span>已到场
                <if condition="$arriveReduceLog"><font color='red'>(超时)</font></if>
                <span class="time fl-right">{BEESCRM:$data.attend_time|date='Y-m-d H:i',###}</span>
            </p>
            <if condition="$imageList">
                <div class="imgs-box clearfix">

                    <volist name="imageList" id="v1">
                        <if condition="$v1['type'] eq 1"><img class="picture fl-left" src="{BEESCRM:$v1.url}"/></if>
                    </volist>

                </div>
            </if>
            <!--已转派的 和已返修的 不显示-->
            <if condition="$data['status'] neq ORDER_RESEND and $data['status'] neq ORDER_FINISHED and $data['status'] neq ORDER_RESET and $data['status'] neq ORDER_REPAIRED and $data['status'] neq ORDER_COMMENTED and $data['order_type_id'] eq 0">
                <div class="label-btn clearfix">
                    <a href="javascript:void(0)" class="submit apply">物料申请</a>
                    <a href="{BEESCRM::U('Repairnew/repairnewMaterial/log',array('repairId'=>$repairId,'order_id'=>$data['order_id'],'apply_type'=>1))}"
                       class="submit" id="record">申请记录</a>
                </div>
            </if>

            <!-- 已维修状态不能申请物料-->
            <if condition="$data['status'] egt ORDER_REPAIRED">
                <div class="label-btn clearfix">
                    <a href="javascript:void(0)" class="submit" style="color:#ccc">物料申请</a>
                    <a href="{BEESCRM::U('Repairnew/repairnewMaterial/log',array('repairId'=>$repairId,'order_id'=>$data['order_id'],'apply_type'=>1))}"
                       class="submit" id="record">申请记录</a>
                </div>
            </if>
        </div>
    </if>

    <!--已转为非日常订单 在已到场后就转-->
    <if condition="$data['order_type_id'] neq 0 and ($data['nodaily_time'] elt $data['finish_time'] or $data['status'] eq ORDER_ATTEND)">
        <div class="dialog clearfix">
            <span class="left-big"></span>
            <span class="left-middle"></span>
            <p>
                <span class="circle orange"></span>
                已转为非日常订单
                <span class="time fl-right">{BEESCRM:$data['nodaily_time']|date='Y-m-d H:i',###}</span>
            </p>
        </div>
    </if>
    <!--已转为非日常订单 end-->

    <!--待维修-->
    <if condition="$data['status'] eq ORDER_ATTEND and $data['order_type'] neq 5 and $data['order_type_id'] eq 0">
        <div class="dialog clearfix">
            <span class="right-big"></span>
            <span class="right-middle"></span>
            <p>
                <span class="circle green"></span>待维修
                <if condition="$repairReduceLog"><font color='red'>(已超时)</font></if>
            </p>
            <p><span>完工操作：</span>
                {BEESCRM:$repairman['real_name']|mb_substr=0,1,'utf8'}师傅　工号：{BEESCRM:$repairman['number']}</p>
            <p><span>完工说明：</span></p>

            <div class="upload-img clearfix">
                <div class="imgbox fl-left">
                    <span id="pic_span"><img style="width:50px;height:50px;" src="" id="picture"/></span>
                </div>
                <div class="add-img fl-left">
                    <input class="file-input" type="file" name="upload-file" id="fileupload_input"/>
                    <span class="iconfont icon-tianjia tianjia"></span>
                    <input type="hidden" id="picture_path" value="">
                </div>
            </div>
            <p class="form-box">
                <textarea class="textarea" placeholder="完工说明描述" id="finish_remark"></textarea>
            </p>

            <div class="label-btn clearfix">
                <a href="{BEESCRM::U('repairnew/repairnewReceive/changeTurn',array('repairId'=>$repairId,'order_id'=>$data['order_id']))}"
                   class="submit" id="changeTurn">申请转派</a>
                <a href="javascript:void(0)" class="submit" id="finish_submit">提交完成</a>
            </div>
        </div>
    </if>

    <!--已维修-->
    <if condition="$data['status'] eq ORDER_REPAIRED or $data['status'] eq ORDER_COMMENTED or $data['status'] eq ORDER_RESET">
        <div class="dialog clearfix">
            <span class="left-big"></span>
            <span class="left-middle"></span>
            <p>
                <span class="circle gray"></span>已维修
                <if condition="$repairReduceLog"><font color='red'>(已超时)</font></if>
                <span class="time fl-right"><if condition="$data.finish_time neq 0">{BEESCRM:$data.finish_time|date='Y-m-d H:i',###}<else/> {BEESCRM:$data.create_time|date='Y-m-d H:i',###}</if></span>
            </p>
            <p><span>维修工：</span>
                <if condition="$repairman['real_name'] neq '' ">
                    {BEESCRM:$repairman['real_name']|mb_substr=0,1,'utf8'}师傅　工号：{BEESCRM:$repairman['number']}
                </if>
            </p>
            <if condition="$imageList">
                <div class="imgs-box clearfix">
                    <volist name="imageList" id="v1">
                        <if condition="$v1['type'] eq 2"><img style="width:50px;height:50px;" class="picture fl-left"
                                                              src="{BEESCRM:$v1.url}"/></if>
                    </volist>
                </div>
            </if>
            <P class="list"><span>完工说明:</span>{BEESCRM:$data.finish_remark}</P>
            <div class="label-btn clearfix">
                <if condition="$rubbishApplyNum gt 0">
                    <a href="{BEESCRM::U('Repairnew/repairnewMaterial/log',array('repairId'=>$repairId,'order_id'=>$data['order_id'],'apply_type'=>3))}"
                       class="submit" style="color:#444;" id="revertRubbish">废料返还记录</a>
                </if>
                <if condition="$rubbishApplyNum eq 0">
                    <a href="{BEESCRM::U('repairnew/repairnewMaterial/revert',array('repairId'=>$repairId,'order_id'=>$data['order_id'],'apply_type'=>3))}"
                       class="submit" style="color:#444;" id="revertRubbish">返还废料</a>
                </if>
                <if condition="$revertApplyNum gt 0">
                    <a href="{BEESCRM::U('Repairnew/repairnewMaterial/log',array('repairId'=>$repairId,'order_id'=>$data['order_id'],'apply_type'=>2))}"
                       class="submit" id="revertMaterial">物料返还记录</a>
                </if>
                <if condition="$revertApplyNum eq 0">
                    <a href="{BEESCRM::U('repairnew/repairnewMaterial/revert',array('repairId'=>$repairId,'order_id'=>$data['order_id'],'apply_type'=>2))}"
                       class="submit" id="revertMaterial">返还物料</a>
                </if>
            </div>
        </div>
    </if>


    <if condition="$data['status'] eq ORDER_REPAIRED">
        <div class="dialog clearfix">
            <span class="left-big"></span>
            <span class="left-middle"></span>
            <p>
                <span class="circle gray"></span>用户未评价
            </p>
            <p>
                <for start="0" end="$data['star']">
                    <span class="iconfont icon-xingxing star small"></span>
                </for>
                <for start="$data['quality_star']" end="4-$data['star']">
                    <span class="iconfont icon-xingxing star small gray-star"></span>
                </for>
            </p>
        </div>
    </if>

    <!--补录订单待审核-->
    <if condition="$data['order_type'] eq 5 and $data['audit'] eq 0 and $data['orgin'] eq 0">
        <div class="dialog clearfix">
            <span class="left-big"></span>
            <span class="left-middle"></span>
            <p>
                <span class="circle gray"></span>待审核
            </p>
        </div>
    </if>

    <!--补录订单未通过放在已维修后面-->
    <if condition="$data['audit'] eq 2 and  $data['order_type'] eq 5">
        <div class="dialog clearfix">
            <span class="left-big"></span>
            <span class="left-middle"></span>
            <p>
                <span class="circle gray"></span>审核未通过
            </p>
        </div>
    </if>

    <if condition="$data['status'] egt ORDER_COMMENTED and $data['status'] neq ORDER_RESET and $data['status'] neq ORDER_FINISHED and $data['status'] neq ORDER_RESEND and ($data['order_type'] eq 1 or $data['order_type'] eq 2 or $data['order_type'] eq 4  or $data['order_type'] eq 5)  and $data['order_type_id'] eq 0">
        <div class="dialog clearfix">
            <span class="left-big"></span>
            <span class="left-middle"></span>
            <p>
                <span class="circle green"></span>
                已评价
            </p>
            <p><span>用户评价：</span> {BEESCRM:$data.comment}</p>
            <p><span>服务星级：</span></p>
            <p>
                <for start="0" end="$data['star']">
                    <span class="iconfont icon-xingxing star small"></span>
                </for>
                <for start="$data['quality_star']" end="4-$data['star']">
                    <span class="iconfont icon-xingxing star small gray-star"></span>
                </for>
            </p>

        </div>
    </if>

    <if condition="$data['status'] eq ORDER_RESET and $data['order_type_id'] eq 0">
        <div class="dialog clearfix">
            <span class="left-big"></span>
            <span class="left-middle"></span>
            <p>
                <span class="circle green"></span>
                已评价
            </p>
            <p><span>用户评价：</span> {BEESCRM:$data.comment}</p>
            <p><span>服务星级：</span></p>
            <p>
                <for start="0" end="$data['star']">
                    <span class="iconfont icon-xingxing star small"></span>
                </for>
                <for start="$data['quality_star']" end="4-$data['star']">
                    <span class="iconfont icon-xingxing star small gray-star"></span>
                </for>
            </p>

        </div>
    </if>

    <!--转派待审核-->
    <if condition="$data['status'] eq ORDER_FINISHED">
        <div class="dialog clearfix">
            <span class="left-big"></span>
            <span class="left-middle"></span>
            <p>
                <span class="circle gray"></span>待转派<span class="time fl-right">{BEESCRM:$data.change_apply_time|date='Y-m-d H:i',###}</span>
            </p>
        </div>
    </if>
    <!--转派待审核-->
    <if condition="$data['status'] eq ORDER_RESEND">
        <div class="dialog clearfix">
            <span class="left-big"></span>
            <span class="left-middle"></span>
            <p>
                <span class="circle gray"></span>已转派<span class="time fl-right">{BEESCRM:$data.change_time|date='Y-m-d H:i',###}</span>
            </p>

        </div>
    </if>
    <!--已返修-->
    <if condition="$data['status'] eq ORDER_RESET">
        <div class="dialog clearfix">
            <span class="left-big"></span>
            <span class="left-middle"></span>
            <p>
                <span class="circle gray"></span>已返修<span class="time fl-right">{BEESCRM:$data.comment_time|date='Y-m-d H:i',###}</span>
            </p>
        </div>
    </if>


</div>

<include file="../commonJS"/>
<script type="text/javascript" src="/assets/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/assets/bower_components/upload/jquery.ui.widget.js"></script>
<script type="text/javascript" src="/assets/bower_components/upload/jquery.fileupload.js"></script>
<script type="text/javascript" src="/assets/bower_components/upload/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="/assets/bower_components/upload/image.compress.js"></script>
<script src="/assets/repairnew/js/fastclick.min.js"></script>
<script>
    $(function () {
        //FastClick.attach(document.body);
        var localObj = window.sessionStorage;
        var psUrl = localObj.getItem('psUrl_{BEESCRM:$data.order_id}');
        //console.log(psUrl)
        if (psUrl) {
            $('#photo').attr('src', psUrl);
            //$('#ps').html('<img style="width:50px;height:50px;" id="photo" src="'+psUrl+'"/>');
        }
        $('#cancel').click(function () {
            $('.layer-wraper').show();
        })

        $('.cancel').click(function () {
            $('.layer-wraper').hide();
        })

        // 图片上传
//		$("#photo_input").fileupload({
//			url:"/base/common/upload",//文件上传地址，当然也可以直接写在input的data-url属性内
//			done:function(e,result){
//				//done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
//				//注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
//				//返回的数据在result.result中，假设我们服务器返回了一个json对象
//				var data=$.parseJSON(result.result);
//				if(data.status=='S'){
//					$('#ps').html('<img style="width:50px;height:50px;" id="photo" src="'+data.url+'"/>');
//				}else{
//					$.alert('error',data.message);
//				}
//			}
//		});
//
//		$("#fileupload_input").fileupload({
//			url:"/base/common/upload",//文件上传地址，当然也可以直接写在input的data-url属性内
//			done:function(e,result){
//				//done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
//				//注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
//				//返回的数据在result.result中，假设我们服务器返回了一个json对象
//				var data=$.parseJSON(result.result);
//				if(data.status=='S'){
//					//$('#picture').attr('src',data.url);
//					$('#pic_span').html('<img style="width:50px;height:50px;" src='+data.url+'  id="picture"/>')
//				}else{
//					$.alert('error',data.message);
//				}
//			}
//		});


        // 图片上传
        var ImageCompressPhoto = new ImageCompressClass({
            fileSelector: "#photo_input",  //fileInput选择器
            previewSelector: "#photo",        //预览图片选择器
            getErrorMessage: function (message) {
                if (message) {
                    $.alert('error', message);
                    return false;
                }
            },
            ajaxInterace: function (image_content) {
                var data = {};
                data.image_content = image_content;
                $.ajax({
                    url: "{BEESCRM::U('repairnew/repairnewReceive/uploadImage',array('repairId'=>$repairId))}",
                    type: 'POST',
                    data: data,
                    dataType: 'JSON',
                    success: function (res) {
                        if (res.status == 'S') {
                            //$.alert('success',res.message);
                            $('#photo_path').val(res.img_url);
                            $('#photo').attr('src', res.img_url);
                        }
                        else {
                            $.alert('error', res.message);
                        }
                    }
                });
            }
        });

        var ImageCompressPicture = new ImageCompressClass({
            fileSelector: "#fileupload_input",  //fileInput选择器
            previewSelector: "#picture",        //预览图片选择器
            getErrorMessage: function (message) {
                if (message) {
                    $.alert('error', message);
                    return false;
                }
            },
            ajaxInterace: function (image_content) {
                var data = {};
                data.image_content = image_content;
                $.ajax({
                    url: "{BEESCRM::U('repairnew/repairnewReceive/uploadImage',array('repairId'=>$repairId))}",
                    type: 'POST',
                    data: data,
                    dataType: 'JSON',
                    success: function (res) {
                        if (res.status == 'S') {
                            //$.alert('success',res.message);
                            $('#picture_path').val(res.img_url);
                            $('#picture').attr('src', res.img_url);
                        }
                        else {
                            $.alert('error', res.message);
                        }
                    }
                });
            }
        });


        //星级评价
        /*$('body').on('click','.star',function(){
         $(this).removeClass('gray-star');
         $(this).prevAll('.star').removeClass('gray-star');
         $(this).nextAll('.star').addClass('gray-star');
         var num = $(this).parent().find('.gray-star').length;
         if( num >= 3){
         $(this).siblings('.level').html('差评');
         }else if( num < 2){
         $(this).siblings('.level').html('好评');
         }else{
         $(this).siblings('.level').html('中评');
         }
         });*/

        //确认订单
        $(document).on('click', '#confirm', function () {
            $.ajax({
                type: 'post',
                url: "{BEESCRM::U('repairnew/repairnewReceive/orderConfirm',array('repairId'=>$repairId))}",
                dataType: 'json',
                data: {
                    'order_id': "{BEESCRM:$data.order_id}"
                },
                success: function (data) {
                    if (data.status == 'S') {
                        $.alert('success', data.message);
                        reload();                    } else {
                        $.alert('error', data.message);
                    }
                },
                error: function () {
                    $.alert('error', '通讯失败，请稍后再试');
                }
            });
        });

        //到场确认
        $(document).on('click', '#arrive', function () {
            var data = {};
            data.order_id = "{BEESCRM:$data.order_id}";
            data.url = $('#photo').attr('src');

            if (!data.url) {
                $.alert('error', '请上传图片');
                return;
            }
            $.ajax({
                type: 'post',
                url: "{BEESCRM::U('repairnew/repairnewReceive/arrive',array('repairId'=>$repairId))}",
                dataType: 'json',
                data: data,
                success: function (data) {
                    if (data.status == 'S') {
                        $.alert('success', data.message);
                        reload();                    } else {
                        $.alert('error', data.message);
                    }
                },
                error: function () {
                    $.alert('error', '通讯失败，请稍后再试');
                }
            });
        })

        //确认完工
        $(document).on('click', '#finish_submit', function () {
            var data = {};
            data.order_id = "{BEESCRM:$data.order_id}";
            data.finish_remark = $('#finish_remark').val();
            if ($('#order_amount').val() != '') {
                data.order_amount = $('#order_amount').val();
            }
            data.url = $('#picture').attr('src');
            if (!data.url) {
                $.alert('error', '请上传图片');
                return;
            }
            $.ajax({
                type: 'post',
                url: "{BEESCRM::U('repairnew/repairnewReceive/orderFinish',array('repairId'=>$repairId))}",
                dataType: 'json',
                data: data,
                success: function (data) {
                    if (data.status == 'S') {
                        $.alert('success', data.message);
                        reload();                    } else {
                        $.alert('error', data.message);
                    }
                },
                error: function () {
                    $.alert('error', '通讯失败，请稍后再试');
                }
            });
        });


        /**
         * 物料申请
         */
        $(document).on('click', '.apply', function () {
            psUrl = $('#ps img').attr('src');
            /*var localObj = window.sessionStorage;*/
            localObj.setItem('psUrl_{BEESCRM:$data.order_id}', psUrl);
            var aa = localObj.getItem('psUrl');
            location.href = "{BEESCRM::U('Repairnew/repairnewMaterial/index',array('repairId'=>$repairId,'order_id'=>$data['order_id']))}"
        })


    });


    //下面这个函数用来转换数组到json格式
    function arrayToJson(o) {
        var r = [];
        if (typeof o == "string") return "\"" + o.replace(/([\'\"\\])/g, "\\$1").replace(/(\n)/g, "\\n").replace(/(\r)/g, "\\r").replace(/(\t)/g, "\\t") + "\"";
        if (typeof o == "object") {
            if (!o.sort) {
                for (var i in o)
                    r.push(i + ":" + arrayToJson(o[i]));
                if (!!document.all && !/^\n?function\s*toString\(\)\s*\{\n?\s*\[native code\]\n?\s*\}\n?\s*$/.test(o.toString)) {
                    r.push("toString:" + o.toString.toString());
                }
                r = "{" + r.join() + "}";
            } else {
                for (var i = 0; i < o.length; i++) {
                    r.push(arrayToJson(o[i]));
                }
                r = "[" + r.join() + "]";
            }
            return r;
        }
        return o.toString();
    }
    //这个是调用微信图片浏览器的函数
    function imagePreview(curSrc, srcList) {
        //这个检测是否参数为空
        if (!curSrc || !srcList || srcList.length == 0) {
            return;
        }
        //这个使用了微信浏览器提供的JsAPI 调用微信图片浏览器
        WeixinJSBridge.invoke('imagePreview', {
            'current': curSrc,
            'urls': srcList
        });
    };

    (function ($) {
        //下面是获取当前页面所有的img的src 转成数组 并且 转换成json格式
        var aa = [];
        var i = 0;
        var src = [];
        var json = null;
        aa = $('img');
        for (i = 0; i < aa.length; i++) {
            src[i] = aa[i].src;    //把所有的src存到数组里
        }
        var srcList = arrayToJson(src); //转换成json并赋值给srcList
        //下面是点击图片的时候获取当前第几个图片并且启用咱们做的调用微信图片浏览器的函数
        $('img').click(function () {
            var index = $('img').index(this);
            imagePreview(src[index], src);
        });

    })(jQuery);
    //刷洗页面
    function reload() {
        window.location.href=window.location.href+"?RAND="+parseInt(100*Math.random());
    }
</script>
</body>

</html>
